﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using FI.Core.Utilities;
using System;

namespace FI.Core.IoC
{
    /// <summary>
    /// This attribute is used to build mapping between service interface and implementation type.
    /// </summary>
    [AttributeUsage( AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
    public sealed class MapToAttribute: Attribute
    {
        #region Properties
        /// <summary>
        /// Gets service interface type.
        /// </summary>
        /// <value>
        /// The service interface type.
        /// </value>
        public Type RegisteredType { get; private set; }

        /// <summary>
        /// Gets or sets the lifetime.
        /// </summary>
        /// <value>
        /// The lifetime.
        /// </value>
        public Lifetime Lifetime { get; set; }

        /// <summary>
        /// Gets the mapping quality.
        /// </summary>
        /// <value>
        /// The mapping quality.
        /// </value>
        public int Quality { get; private set; }


        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name { get; set; }

        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="MapToAttribute"/> class.
        /// </summary>
        /// <param name="registeredType">Type of the registered.</param>
        /// <param name="quality">The quality.</param>
        public MapToAttribute(Type registeredType, int quality = 0)
        {
            Guard.ArgumentNotNull(registeredType, "registeredType");

            this.RegisteredType = registeredType;
            this.Quality = quality;
            this.Lifetime = Lifetime.Transient;
        }
        #endregion
    }
}
